<script setup>
import { ref } from 'vue';
import { useRouter, useRoute } from 'vue-router'
import { request } from '../../../utils';
import{Toast}from 'vant'
const router = useRouter()
const value = ref('')
const datalist = ref([])


const search = async function (value){
    const {data}= await request.get('/goods/search',{
        params:{
            keyword:value
        }
        
    })
    console.log(data);
    if(data.data.length === 0){
        Toast.fail('没有该商品')
        console.log(666);
    }
    // if(value !== ''){
    //     datalist.value = data.data
        
    // }else {
    //     datalist.value = ''
    // }/
   
    value ? datalist.value = data.data : datalist.value = ''
    
}


const onClickLeft = function () {
   
    router.go(-1)
}
</script>
<template>
    <div>
        <van-nav-bar title="库存查询" left-text="菜单功能" left-arrow @click-left="onClickLeft" class="vipnav"
            :border="false" />
        <van-search v-model="value" placeholder="请输入搜索关键词" @update:model-value="search(value)" />
        <van-card :num="'库存'+item.qty" :price="item.price+'元'" :title="item.goodsname"
            thumb="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F1114%2F121R0113012%2F20121Q13012-6-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1664950482&t=0d1147c736ed632070b11fa0d0663d22"  v-for="item in datalist" :key="item.name"/>
    </div>
</template>